<?php

	require_once('../../config.php');
	require_once('security.php');    
    
   // Retrieve the file contents
	$page = $_GET['page'];
	$filename = "../imgtxt/$page";
	if (file_exists($filename))
	{
		// Get the contents
		$file_contents = file_get_contents($filename);
		
		#$file_contents = htmlspecialchars($file_contents);//convert special character into html entities
	}

	// Apend
	if (isset($_POST['submit1']))
	{ // Handle the form.
		$content = $_POST['addtext'];
		$content = stripslashes($content);
		$page = $_POST['page'];
		$filename = '../imgtxt/' . $page;
		$fp = fopen($filename, "a") or die("Couldn't open $filename.");
		fwrite($fp, "\n$content");
		fclose($fp);
		$response = "The content was added.";
	}

	// Over-write
	if (isset($_POST['submit2']))
	{ // Handle the form.
		$content = $_POST['addtext'];
		$content = stripslashes($content);
		$page = $_POST['page'];
		$filename = '../imgtxt/' . $page;
		$fp = fopen($filename, "w") or die("Couldn't open $filename.");
		fwrite($fp, "$content");
		fclose($fp);
		$response = "The content was overwritten.";
	}
  
?>

<?php $thisPage = "txtFileToBeEdit"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Text File To Be Edit page content</title>
<meta name="robots" content="noindex,nofollow" />
<?php require_once('theme/admintheme.php');?>
</head>
<body>

<div id="wrap">





<?php include_once('navigation.php'); ?>

<?php echo 'Page = ' . $page . '<br />'; ?>
Path to text file = <?php echo "../imgtxt/" . "$page"; ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" accept-charset="UTF-8">
<textarea class="textarea" name="addtext" cols="70" rows="25"><?php if ((isset($_POST['submit1'])) || (isset($_POST['submit2']))) { echo htmlspecialchars(stripslashes($_POST['addtext'])); } else { echo $file_contents; } ?></textarea><br />
<input type="hidden" name="page" value="<?php echo $page; ?>" />
<input type="submit" name="submit1" value="Append" /> <input type="submit" name="submit2" value="Overwrite" />
</form>

<?php
	echo $response;
    echo '<a href="'. $wwwroot . '/cms/imgtxt/' . $page . '">View &raquo;</a>';

?>



</div>

</body>
</html>